
const TokenKey = 'mobile-mooc-Token'

// 获取token
export function getToken() {
  return getStorage(TokenKey)
}
// 设置token
export function setToken(token) {
  setStorage(TokenKey, token)
}
// 删除token
export function removeToken() {
  removeStorage(TokenKey)
}

export function getStorage(key) {
  const data = window.sessionStorage.getItem(key)
  if (data) {
    return JSON.parse(data)
  } else {
    return null
  }
}

export function setStorage(key, data) {
  // 只能存字符串
  const dataStr = JSON.stringify(data)
  //   window.localStorage.setItem(key, dataStr)
  window.sessionStorage.setItem(key, dataStr)
}

export function removeStorage(key) {
  return window.sessionStorage.removeItem(key)
}
